package teste;

import java.util.ArrayList;
import java.util.List;

import Negocio.Tweet;
import persistencia.Twitter_DAO;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class ColetaDados {

	/**
	 * @param args
	 */
	private static final String TWITTER_CONSUMER_KEY = "inLKLFZz522uYRkGF7ZYNKvX3";
	private static final String TWITTER_SECRET_KEY = "QkGqR6W6yGwfRLpVJjzCvLjNnmXUrwVMeo8fb6M14xZal3tNSs";
	private static final String TWITTER_ACCESS_TOKEN = "63195531-WkgsFrL3FCICmXPGBuZsJLYfD9NTjQqMOrt6rklzu";
	private static final String TWITTER_ACCESS_TOKEN_SECRET = "0sxnMc17hBNbJGnBNaAJ0xDUsTAykstODiAkHk1LMnHvy";
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		

		ConfigurationBuilder cb = new ConfigurationBuilder();
		cb.setDebugEnabled(true)
		    .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
		    .setOAuthConsumerSecret(TWITTER_SECRET_KEY)
		    .setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
		    .setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
		TwitterFactory tf = new TwitterFactory(cb.build());
		Twitter twitter = tf.getInstance();
		
		try {
			String chave = "Dilma";
			String hashtag =null;
		    Query query = new Query(chave);
		    QueryResult result;
		    do {
		        result = twitter.search(query);
		        List<Status> tweets = result.getTweets();
		        Tweet twit = new Tweet();
		        Twitter_DAO dao = new Twitter_DAO();
		        for (Status tweet : tweets) {
		            System.out.println("@" + tweet.getUser().getScreenName() + " - "+tweet.getCreatedAt()+" - " + tweet.getText());
		            
		            //preenchimento do twitter
		            twit.setUsuario(tweet.getUser().getScreenName());
		            twit.setData(tweet.getCreatedAt());
		            twit.setTexto(tweet.getText());
		            dao.inserir(twit,chave,hashtag);
		            
		        }
		    } while ((query = result.nextQuery()) != null);
		    System.exit(0);
		} catch (TwitterException te) {
		    te.printStackTrace();
		    System.out.println("Failed to search tweets: " + te.getMessage());
		    System.exit(-1);
		}



	}

}
